<template>
  <div>
    <el-table :data="seckillList" border style="width: 100%">
      <el-table-column prop="title" label="活动名称"> </el-table-column>
      <el-table-column label="开始时间">
        <template slot-scope="scoped">
          <div>
            {{ new Date(Number(scoped.row.begintime)).toLocaleDateString() }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="结束时间">
        <template slot-scope="scoped">
          <div>
            {{ new Date(Number(scoped.row.endtime)).toLocaleDateString() }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scoped">
          <div>
            <el-button v-if="scoped.row.status == 1" type="primary"
              >启 用</el-button
            >
            <el-button v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编 辑</el-button>
            <el-button type="primary" @click="del(scoped.row.id)"
              >删 除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { seckDelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";

export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      seckillList: "seckill/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncSeckillList: "seckill/asyncChangeList",
    }),
    del(id) {
      seckDelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.asyncSeckillList();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    edit(id) {
      this.$emit("edit", id);
    },
  },
  mounted() {
    this.asyncSeckillList();
  },
};
</script>
<style scoped>
</style>